import { mapState } from "vuex"

export default {
    computed: {
        ...mapState(['details'])
    },
    created () {
        console.log(this.details);
        if (this.details) {
            this.formConfig.formData = { ...this.details }
        }
    },
    methods: {
        async submit (data) {
            let interfaceType = data.addApi;
            let message = data.addMsg || '添加成功！';
            if (this.details) {
                interfaceType = data.editApi;
                message = data.editMsg || '编辑成功！';
            }
            const res = await this.$api[interfaceType](data.form);
            res && this.$message({
                message,
                type: 'success'
            });
            this.$router.back();
        }
    },
}
